<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <?php
        require_once 'conn.php';
        // 获取用户信息
        $name = $_POST['name'];
        $password = $_POST['password'];
        if($_POST['sex'] == '男'){
            $sex = 1;
        }
        else if($_POST['sex'] == '女'){
            $sex = 2;
        }
        else {
            $sex = 3;
        }
        $age = $_POST['age'];
        $hobby = $_POST['hobby'];
        $detail = $_POST['detail'];
        mysqli_query($con, "INSERT INTO user (name, password, sex, age, hobby, detail) VALUES ('$name', '$password', '$sex', '$age', '$hobby', '$detail')");
        $rows = mysqli_affected_rows($con);
        if($rows >= 1){
            echo "添加成功";
            header("Location: list.php");
            exit;
        }
        else {
            echo "添加失败";
        }
    ?>
</body>
</html>
